<template>
	<view>
		<u-navbar placeholder fixed autoBack border title="培训"></u-navbar>
		<view class="d-p-30">
			<view><text class="d-font-36" style="font-weight: bold;">培训概览</text></view>

			<view class="card d-m-t-30 d-p-30 d-flex d-text-center">
				<view class="d-flex-1">
					<view style="color: #162233;font-size: 52rpx;font-weight: bold;">{{ appto ? appto.value : 0 }}</view>
					<view class="d-font-24" style="color: #162233;">培训次数</view>
				</view>
				<view class="d-flex-1">
					<view style="color: #162233;font-size: 52rpx;font-weight: bold;">{{ appto ? appto.staffs : 0 }}</view>
					<view class="d-font-24" style="color: #162233;">累积人次</view>
				</view>
			</view>
			<view class="d-m-t-30"><text class="d-font-36" style="font-weight: bold;">培训记录</text></view>

			<template v-if="list && list.length > 0">
				<view class="card d-m-t-30 d-p-30" v-for="(item, index) in list" :key="index">
					<view class="d-m-b-20 d-flex">
						<view class="d-font-28 d-flex-1" style="font-weight: bold;">{{ item.kcmc }}</view>
						<view>
							<u-button
								text="查看"
								size="mini"
								type="info"
								shape="circle"
								:customStyle="{
									color: '#FFB61D',
									borderColor: '#FFB61D'
								}"
								@click="trainDetail(item)"
							></u-button>
						</view>
					</view>
					<view class="d-flex" style="color: #5D6672;">
						<view class="d-flex-1 d-font-28 d-flex">
							<text style="">培训讲师</text>
							<text class="d-m-l-20 d-flex-1 u-line-1" style="color:#162233;max-width: 200rpx;">{{ item.jsmc }}</text>
						</view>
						<view class="d-flex-1 d-font-28">
							<text style="">开始时间</text>
							<text class="d-m-l-20" style="color:#162233;">{{ item.pxksrq }}</text>
						</view>
					</view>
					<view class="d-flex d-m-t-20" style="color: #5D6672;">
						<view class="d-flex-1 d-font-28">
							<text style="">培训人数</text>
							<text class="d-m-l-20" style="color:#162233;">{{ item.pxrs }}人</text>
						</view>
						<view class="d-flex-1 d-font-28">
							<text style="">结束时间</text>
							<text class="d-m-l-20" style="color:#162233;">{{ item.pxjsrq }}</text>
						</view>
					</view>
				</view>
			</template>
			<template v-else>
				<view style="padding: 10vh;"><u-empty icon="/static/image/none.png" text="暂无数据"></u-empty></view>
			</template>
		</view>
	</view>
</template>

<script>
import { getAppto, getTrain } from '../../../common/api.js';
export default {
	data() {
		return {
			appto: null,
			pageNum: 1,
			pageSize: 20,
			pageLast: 1,
			list: []
		};
	},
	onLoad() {
		this.init();
	},
	onReachBottom() {
		if (this.pageNum < this.pageLast) {
			++this.pageNum;
			this.getTrain().then(e => {
				this.list = this.list.concat(e.data);
			});
		}
	},
	methods: {
		init() {
			getAppto()
				.then(e => {
					this.appto = e.data;
					return this.getTrain();
				})
				.then(e => {
					this.pageLast = Math.ceil(e.total / this.pageSize);
					this.list = e.data;
				});
		},
		getTrain() {
			return getTrain({
				params: {
					bzid: this.$user.ssgcxx[this.$appIndex].bzid // 班组id【必传】
				}
			});
		},
		trainDetail(item) {
			uni.$u.toast('接口对不上');
			uni.$u.route({
				url: '/pages/index/train/trainDetail',
				params: {
					id: item.id,
					pxrs: item.pxrs
				}
			});
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #fbfcfc;
	.card {
		box-shadow: 0rpx 5rpx 10rpx rgba(0, 0, 0, 0.05);
		border-radius: 10rpx;
		background-color: #ffffff;
	}
}
</style>
